//
//  CPNetworkTool.swift
//  weibo
//
//  Created by zcp on 16/5/12.
//  Copyright © 2016年 zcp. All rights reserved.
//

import UIKit
import AFNetworking
//POST/GET枚举
enum requsetMethod: String{

    case POST = "POST"
    case GET = "GET"
}
class CPNetworkTool: NSObject {
    //网络请求数据单例
    static let sharedNetworkTool: CPNetworkTool = CPNetworkTool()
    //请求属性
//    let afnManger = AFHTTPSessionManager(baseURL: NSURL(string: "https://api.weibo.com/"))
    let afnManger:AFHTTPSessionManager = {
    
        let afn = AFHTTPSessionManager(baseURL: NSURL(string: "https://api.weibo.com/"))
        afn.responseSerializer.acceptableContentTypes?.insert("text/plain")
        
        return afn
    
    }()

    //请求数据的方法
    func request (method: requsetMethod,URLString: String, parameters: AnyObject?, success: ((NSURLSessionDataTask, AnyObject?) -> Void)?, failure: ((NSURLSessionDataTask?, NSError) -> Void)?){
        if method == requsetMethod.GET
        {
            afnManger.GET(URLString, parameters: parameters, progress: nil, success: success, failure: failure)
        }
        else
        {
            afnManger.POST(URLString, parameters: parameters, progress: nil, success: success, failure: failure)
            
        }
    }
    
    

}
